import 'dart:io';

import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart';
import '../../constants.dart';
import '../http/base_dio.dart';

part 'partner_api.g.dart';

@RestApi(baseUrl: kBaseUrl)
abstract class PartnerApi {
  factory PartnerApi({Dio dio, String baseUrl}) {
    dio ??= BaseDio.getInstance().getDio();
    return _PartnerApi(dio, baseUrl: baseUrl);
  }

  @GET("/api/v1/edupartnerfiledir") //获取目录
  Future<GetDirResponse> getDir();

  @GET("/api/v1/edupartnerfileinfo") //拉取图片列表
  Future<FileListResponse> fileList(
      @Query("pId") int pId, @Query("pg") int page, @Query("size") int size);

  @POST("/api/v1/edupartnerfiledir") //创建目录
  Future<CreateDirResponse> createDir(@Body() DirBody body);

  @POST("/api/v1/uploadfile/partnerpictures") //创建目录
  Future<UploadResponse> upload(@Part(value: "type") int type, @Part(value: "syncPublish") int syncPublish,
      @Part(value: "pId") int pId, @Part(value: "file") File file);
}

@JsonSerializable()
class GetDirResponse {
  String requestId;
  int code;
  String msg;

  GetDirResponse({this.code, this.msg, this.requestId});

  factory GetDirResponse.fromJson(Map<String, dynamic> json) =>
      _$GetDirResponseFromJson(json);
}

@JsonSerializable()
class FileListResponse {
  String requestId;
  int code;
  String msg;

  FileListResponse({this.code, this.msg, this.requestId});

  factory FileListResponse.fromJson(Map<String, dynamic> json) =>
      _$FileListResponseFromJson(json);
}

@JsonSerializable()
class DirBody {}

@JsonSerializable()
class CreateDirResponse {
  String requestId;
  int code;
  String msg;

  CreateDirResponse({this.code, this.msg, this.requestId});

  factory CreateDirResponse.fromJson(Map<String, dynamic> json) =>
      _$CreateDirResponseFromJson(json);
}

@JsonSerializable()
class UploadResponse {
  String requestId;
  int code;
  String msg;

  UploadResponse({this.code, this.msg, this.requestId});

  factory UploadResponse.fromJson(Map<String, dynamic> json) =>
      _$UploadResponseFromJson(json);
}
